//
//  ZFMyViewController.m
//  HappyLoan
//
//  Created by zainishenbian on 2017/3/16.
//  Copyright © 2017年 zongqingxiangqian. All rights reserved.
//

#import "ZFMyViewController.h"
#import "ZFBaseViewController1.h"//基本信息VC1
#import "ZFBaseInfoViewController2.h"//社会信息VC
#import "ZFAuthorizeInfoViewController.h"//授权信息VC
#import "ZFBindCardViewController.h"//绑定银行卡
#import "ZFFaceInfoViewController.h"//人脸识别VC

#import "ZFBilViewController.h"//账单
#import "ZFPersonInfoViewController.h"//个人信息
#import "ZFFeedbackViewController.h"//意见反馈
#import "ZFBindedCardViewController.h"//收扣款银行卡
#import "SetUpViewController.h"
#import "ZFHeader.h"
#import "ZLCLinkUrlViewController.h"
#import "ZLCAboutUsViewController.h"

@interface ZFMyViewController ()

@property (nonatomic,strong) AlertBoxView *alertV;
@end

@implementation ZFMyViewController

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    self.navigationController.navigationBarHidden = YES;
    [MobClick beginLogPageView:@"myView"];
    [self changeUserlabelStatu];
}
- (void)viewDidLoad {
    
    [super viewDidLoad];
    
    [self initData];
    

    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(userStatus:)];
    [_userLabel addGestureRecognizer:tap];
}

- (void)initData
{
    _bankLabel.hidden = YES;
    
    _alertV = [[AlertBoxView alloc] init];
    [self.view addSubview:_alertV];

    //禁止侧滑
    self.navigationController.interactivePopGestureRecognizer.enabled = NO;
}
#pragma mark ———— label的点击事件
- (void)userStatus:(UITapGestureRecognizer *)tap
{
    UILabel *label = (UILabel *)[tap view];
    if ([label.text isEqualToString:@"请登录"]) {
        
        UIViewController *loginVC = [ZFLoginConfig getLoginVC2];
        [self presentViewController:loginVC animated:YES completion:nil];
        return;
    }
}
#pragma mark ———— button的点击事件
//设置
- (IBAction)setUpBuotton:(UIButton *)sender {
    
    if (![ZFLoginConfig isLogined]) {
        
        UIViewController *loginVC = [ZFLoginConfig getLoginVC2];
        [self presentViewController:loginVC animated:YES completion:nil];
        return;
    }
    SetUpViewController *setUpVC = [[SetUpViewController alloc] init];
    setUpVC.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:setUpVC animated:YES];
}
//消息
- (IBAction)messageClick:(id)sender {
    
    if (![ZFLoginConfig isLogined]) {
        
        UIViewController *loginVC = [ZFLoginConfig getLoginVC2];
        [self presentViewController:loginVC animated:YES completion:nil];
        return;
    }
    UITabBarController *tabbar = (UITabBarController *)[UIApplication sharedApplication].delegate.window.rootViewController;
    tabbar.selectedIndex = 1;
}
//个人信息
- (IBAction)personInfo:(id)sender {
    
    if (![ZFLoginConfig isLogined]) {
        
        UIViewController *loginVC = [ZFLoginConfig getLoginVC2];
        [self presentViewController:loginVC animated:YES completion:nil];
        return;
    }
    
    UIViewController *VC = nil;
    NSLog(@"%ld",[ZFPulicAPI getsaveInfoProgress]);
    switch ([ZFPulicAPI getsaveInfoProgress]) {
        case 1:
        {
            VC = [ZFBaseViewController1 new];
        }
            break;
        case 2:
        {
            VC = [ZFBaseInfoViewController2 new];
        }
            break;
        case 3:
        {
            VC = [ZFAuthorizeInfoViewController new];
        }
            break;
        case 4:
        {
            VC = [ZFBindCardViewController new];
        }
            break;
        case 5:
        {
            VC = [ZFFaceInfoViewController new];
        }
            break;
        case 6:
        {
            VC = [ZFPersonInfoViewController new];
        }
        default:
            break;
    }
    VC.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:VC animated:YES];
}
//列表点击事件
- (IBAction)listTapClick:(id)sender {
    
    if (![ZFLoginConfig isLogined]) {
        UIViewController *loginVC = [ZFLoginConfig getLoginVC2];
        [self presentViewController:loginVC animated:YES completion:nil];
        return;
    }
    UIButton *button = (UIButton *)sender;
    switch (button.tag) {
        case 1:
            {
                ZFBilViewController *billVC = [ZFBilViewController new];
                billVC.hidesBottomBarWhenPushed = YES;
                [self.navigationController pushViewController:billVC animated:YES];
            }
            break;
        case 2:
            {
                if ([ZFPulicAPI getsaveInfoProgress] >= 5) {
                    
                    ZFBindedCardViewController *bindedVC = [ZFBindedCardViewController new];
                    bindedVC.hidesBottomBarWhenPushed = YES;
                    [self.navigationController pushViewController:bindedVC animated:YES];
                }
                else
                {
                    [_alertV appearAndDisappearAlertWithString:@"亲~ 请先完成认证信息"];
                }
            }
            break;
        case 3:
            {
                ZLCLinkUrlViewController *linkUrlVC = [[ZLCLinkUrlViewController alloc] init];
                linkUrlVC.titleStr = @"帮助中心";
                linkUrlVC.url = @"http://106.15.102.162/static/help/index.html";
                linkUrlVC.hidesBottomBarWhenPushed = YES;
                [self.navigationController pushViewController:linkUrlVC animated:YES];
            
            }
            break;

        case 4:
            {
                //打电话
                [self performSelector:@selector(makeCall) withObject:nil afterDelay:0.0];
                
            }
            break;

        case 5:
            {
                ZFFeedbackViewController *feedVC = [ZFFeedbackViewController new];
                feedVC.hidesBottomBarWhenPushed = YES;
                [self.navigationController pushViewController:feedVC animated:YES];
            }
            break;

        case 6:
            {
                ZLCAboutUsViewController *linkUrlVC = [[ZLCAboutUsViewController alloc] init];
                linkUrlVC.hidesBottomBarWhenPushed = YES;
                [self.navigationController pushViewController:linkUrlVC animated:YES];
            }
            break;

            
        default:
            break;
    }
}
- (void)makeCall{
    NSString *str = [NSString stringWithFormat:@"tel:%@",@"4008296939"];
    
    UIWebView *callWebView = [[UIWebView alloc]init];
    
    [callWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:str]]];
    
    [self.view addSubview:callWebView];
}

#pragma mark ———— 登录status，改变 userlabel
- (void)changeUserlabelStatu
{
    if (![ZFLoginConfig isLogined]) {
        
        _userLabel.text = @"请登录";
    }
    else
    {
        _userLabel.text = [[NSUserDefaults standardUserDefaults] objectForKey:@"phone"];
    }

}
- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    [MobClick endLogPageView:@"myView"];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
